const express = require('express')
const auth = require('../middleware/auth')
const router = express.Router()

// 获取安全告警
router.get('/alerts', auth, (req, res) => {
  try {
    const alerts = [
      {
        id: '1',
        type: 'intrusion',
        level: 'high',
        message: '检测到异常入侵',
        location: 'A区入口',
        timestamp: new Date().toISOString(),
        status: 'active'
      },
      {
        id: '2',
        type: 'fire',
        level: 'medium',
        message: '烟雾报警器触发',
        location: '办公楼2层',
        timestamp: new Date(Date.now() - 1800000).toISOString(),
        status: 'resolved'
      }
    ]

    res.json({
      success: true,
      data: alerts,
      total: alerts.length
    })
  } catch (error) {
    console.error('Get security alerts error:', error)
    res.status(500).json({
      success: false,
      error: '获取安全告警失败'
    })
  }
})

// 获取安全事件
router.get('/events', auth, (req, res) => {
  try {
    const events = [
      {
        id: '1',
        type: 'access',
        description: '员工刷卡进入',
        location: '主入口',
        user: '张三',
        timestamp: new Date().toISOString()
      }
    ]

    res.json({
      success: true,
      data: events,
      total: events.length
    })
  } catch (error) {
    console.error('Get security events error:', error)
    res.status(500).json({
      success: false,
      error: '获取安全事件失败'
    })
  }
})

module.exports = router